//
//  UserModel.swift
//
//  Created by Icy on 2017/1/11
//  Copyright (c) . All rights reserved.
//

import Foundation
import SwiftyJSON
import ModelProtocol

 class UserModel: ModelProtocol {

    // MARK: Declaration for string constants to be used to decode and also serialize.
	internal let kUserAddressKey: String = "address"
	internal let kUserOfficeKey: String = "office"
	internal let kUserPostcodeKey: String = "postcode"
	internal let kUserLastnameKey: String = "lastname"
	internal let kUserFirstnameKey: String = "firstname"
	internal let kUserAvatarKey: String = "avatar"
	internal let kUserEmailKey: String = "email"
	internal let kUserCountrycodeKey: String = "countrycode"
	internal let kUserHomeKey: String = "home"
	internal let kUserGenderKey: String = "gender"
	internal let kUserInternalIdentifierKey: String = "id"
	internal let kUserTokenKey: String = "token"
	internal let kUserPhoneKey: String = "phone"
	internal let kUserPasswordKey: String = "password"
	internal let kUserAuthorisedKey: String = "authorised"
	internal let kUserCreatedateKey: String = "createdate"


    // MARK: 属性
	 var address: String!
	 var office: String!
	 var postcode: String!
	 var lastname: String!
	 var firstname: String!
	 var avatar: String!
	 var email: String!
	 var countrycode: String!
	 var home: String!
	 var gender: String!
	 var internalIdentifier: Int!
	 var token: String!
	 var phone: String!
	 var password: String!
	 var authorised: Bool = false
	 var createdate: String!


    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
		address = json[kUserAddressKey].stringValue
		office = json[kUserOfficeKey].stringValue
		postcode = json[kUserPostcodeKey].stringValue
		lastname = json[kUserLastnameKey].stringValue
		firstname = json[kUserFirstnameKey].stringValue
		avatar = json[kUserAvatarKey].stringValue
		email = json[kUserEmailKey].stringValue
		countrycode = json[kUserCountrycodeKey].stringValue
		home = json[kUserHomeKey].stringValue
		gender = json[kUserGenderKey].stringValue
		internalIdentifier = json[kUserInternalIdentifierKey].intValue
		token = json[kUserTokenKey].stringValue
		phone = json[kUserPhoneKey].stringValue
		password = json[kUserPasswordKey].stringValue
		authorised = json[kUserAuthorisedKey].boolValue
		createdate = json[kUserCreatedateKey].stringValue

    }


    /**
    Generates description of the object in the form of a NSDictionary.
    - returns: A Key value pair containing all valid values in the object.
    */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {

        var dictionary: [String : AnyObject ] = [ : ]
		if address != nil {
			dictionary.updateValue(address! as AnyObject, forKey: kUserAddressKey)
		}
		if office != nil {
			dictionary.updateValue(office! as AnyObject, forKey: kUserOfficeKey)
		}
		if postcode != nil {
			dictionary.updateValue(postcode! as AnyObject, forKey: kUserPostcodeKey)
		}
		if lastname != nil {
			dictionary.updateValue(lastname! as AnyObject, forKey: kUserLastnameKey)
		}
		if firstname != nil {
			dictionary.updateValue(firstname! as AnyObject, forKey: kUserFirstnameKey)
		}
		if avatar != nil {
			dictionary.updateValue(avatar! as AnyObject, forKey: kUserAvatarKey)
		}
		if email != nil {
			dictionary.updateValue(email! as AnyObject, forKey: kUserEmailKey)
		}
		if countrycode != nil {
			dictionary.updateValue(countrycode! as AnyObject, forKey: kUserCountrycodeKey)
		}
		if home != nil {
			dictionary.updateValue(home! as AnyObject, forKey: kUserHomeKey)
		}
		if gender != nil {
			dictionary.updateValue(gender! as AnyObject, forKey: kUserGenderKey)
		}
		if internalIdentifier != nil {
			dictionary.updateValue(internalIdentifier! as AnyObject, forKey: kUserInternalIdentifierKey)
		}
		if token != nil {
			dictionary.updateValue(token! as AnyObject, forKey: kUserTokenKey)
		}
		if phone != nil {
			dictionary.updateValue(phone! as AnyObject, forKey: kUserPhoneKey)
		}
		if password != nil {
			dictionary.updateValue(password! as AnyObject, forKey: kUserPasswordKey)
		}
		dictionary.updateValue(authorised as AnyObject, forKey: kUserAuthorisedKey)
		if createdate != nil {
			dictionary.updateValue(createdate! as AnyObject, forKey: kUserCreatedateKey)
		}

        return dictionary
    }


}
